home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Cappuccino / Source / CappuccinoClipboard.cpp < prev    next >
Encoding:
Text File  |  1995-12-11  |  7.7 KB  |  325 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CappuccinoClipboard.cpp
  3.     
  4.     Contents:    Implements cut, copy, paste, and clear support.
  5.     
  6.     Written by:    Troy Gaul
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // -- Compiler/Preprocessor Switches --
  12.  
  13. #ifndef _COMPILERDEFS_
  14. #include "CompDefs.h"
  15. #endif
  16.  
  17. // -- OpenDoc Utilities --
  18.  
  19. #ifndef _EXCEPT_
  20. // Exceptions define several important macros (eg. CHECKENV)
  21. // which are used in the SOM method dispatch glue. If Except.h
  22. // is not included early enough, exceptions may not be thrown
  23. // correctly when returning from a SOM method with the "ev" parameter set.
  24. #include <Except.h>
  25. #endif
  26.  
  27. // -- Cappuccino Includes --
  28.  
  29. #ifndef _CAPPUCCINO_
  30. #include "Cappuccino.h"
  31. #endif
  32.  
  33. #ifndef _CAPPUCCINOACTION_
  34. #include "CappuccinoAction.h"
  35. #endif
  36.  
  37. #ifndef _CAPPUCCINOCONTENT_
  38. #include "CappuccinoContent.h"
  39. #endif
  40.  
  41. #ifndef _CAPPUCCINODEF_
  42. #include "CappuccinoDef.h"
  43. #endif
  44.  
  45. #ifndef _CAPPUCCINOGLOBALS_
  46. #include "CappuccinoGlobals.h"
  47. #endif
  48.  
  49. #ifndef _TEMPFOCUS_
  50. #include "TempFocus.h"
  51. #endif
  52.  
  53. // -- OpenDoc Includes --
  54.  
  55. #ifndef SOM_ODClipboard_xh
  56. #include <Clipbd.xh>
  57. #endif
  58.  
  59. #ifndef SOM_Module_OpenDoc_Commands_defined
  60. #include <CmdDefs.xh>
  61. #endif
  62.  
  63. #ifndef SOM_ODMenuBar_xh
  64. #include <MenuBar.xh>
  65. #endif
  66.  
  67. #ifndef SOM_ODSession_xh
  68. #include <ODSessn.xh>
  69. #endif
  70.  
  71. #ifndef _ODTYPES_
  72. #include <ODTypes.h>
  73. #endif
  74.  
  75. #ifndef SOM_ODTranslation_xh
  76. #include <Translt.xh>
  77. #endif
  78.  
  79. // -- OpenDoc Utilities --
  80.  
  81. #ifndef _FOCUSLIB_
  82. #include <FocusLib.h>
  83. #endif
  84.  
  85. #ifndef _ODDEBUG_
  86. #include <ODDebug.h>
  87. #endif
  88.  
  89. #ifndef _ODUTILS_
  90. #include <ODUtils.h>
  91. #endif
  92.  
  93. #ifndef _STDTYPIO_
  94. #include <StdTypIO.h>
  95. #endif
  96.  
  97. #ifndef _STORUTIL_
  98. #include <StorUtil.h>
  99. #endif
  100.  
  101. #ifndef _TEMPOBJ_
  102. #include <TempObj.h>
  103. #endif
  104.  
  105.  
  106. //------------------------------------------------------------------------------
  107. // Method:        IsClipboardComandEnabled
  108. // Origin:        Cappuccino
  109. //
  110. // Description:    This method is called by AdjustMenus to determine if an Edit
  111. //                menu command is enabled.
  112. //------------------------------------------------------------------------------
  113.  
  114. void Cappuccino::AdjustClipboardComands( Environment*        ev,
  115.                                          ODFrame*            frame )
  116. {
  117.     SOM_Trace("Cappuccino","IsClipboardAcceptable");
  118.     
  119.     ASSERT_NOT_NULL(frame);
  120.  
  121.     ODBoolean hasText = !fContent->IsEmpty();
  122.     
  123.     gGlobals->fMenuBar->EnableCommand(ev, kODCommandCopy, hasText);
  124.  
  125. #ifndef qViewerBuild
  126.     ODBoolean hasValidData = kODFalse;
  127.     ODBoolean needsTranslation = kODFalse;
  128.  
  129.     if (!fReadOnlyStorage)
  130.     {
  131.         TempClipboardFocus clipboardFocus(ev, frame);
  132.         if ( clipboardFocus.Request() )
  133.         {
  134.             ODClipboard* clipboard = fSession->GetClipboard(ev);
  135.             ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
  136.             
  137.             hasValidData = CCappuccinoContent::HasValidContent(ev, clipboardSU, 
  138.                                                                &needsTranslation);
  139.         }
  140.     }
  141.  
  142.     gGlobals->fMenuBar->EnableCommand(ev, kODCommandCut,
  143.                 !fReadOnlyStorage && hasText);
  144.     
  145.     gGlobals->fMenuBar->EnableCommand(ev, kODCommandPaste,
  146.                 !fReadOnlyStorage && hasValidData);
  147.         
  148.     gGlobals->fMenuBar->EnableCommand(ev, kODCommandPasteAs,
  149.                 !fReadOnlyStorage && hasValidData && needsTranslation);
  150.  
  151.     gGlobals->fMenuBar->EnableCommand(ev, kODCommandClear,
  152.                 !fReadOnlyStorage && hasText);
  153. #else
  154.     gGlobals->fMenuBar->EnableCommand(ev, kODCommandCut,     kODFalse);
  155.     gGlobals->fMenuBar->EnableCommand(ev, kODCommandPaste,   kODFalse);
  156.     gGlobals->fMenuBar->EnableCommand(ev, kODCommandPasteAs, kODFalse);
  157.     gGlobals->fMenuBar->EnableCommand(ev, kODCommandClear,   kODFalse);
  158. #endif    
  159. }
  160.  
  161. //------------------------------------------------------------------------------
  162. // Method:        DoCut
  163. // Origin:        Cappuccino
  164. //
  165. // Description:    This method is called by the part when the user chooses the
  166. //                Cut menu item.
  167. //------------------------------------------------------------------------------
  168.  
  169. void Cappuccino::DoCut( Environment*        ev,
  170.                         ODFrame*            frame )
  171. {
  172.     SOM_Trace("Cappuccino","DoCut");
  173.  
  174. #ifndef qViewerBuild
  175.     ASSERT_NOT_NULL(frame);
  176.  
  177.     if ( !this->TryToEdit(ev, frame) )
  178.         return;
  179.  
  180.     // Copy our current content to the clipboard.
  181.     this->DoCopy(ev, frame);
  182.     
  183.     CCutAction* action = new CCutAction(this);
  184.     action->Perform(ev);
  185. #endif
  186. }
  187.  
  188. //------------------------------------------------------------------------------
  189. // Method:        DoCopy
  190. // Origin:        Cappuccino
  191. //
  192. // Description:    This method is called by the part when the user chooses the
  193. //                Copy menu item.
  194. //------------------------------------------------------------------------------
  195.  
  196. void Cappuccino::DoCopy( Environment*        ev,
  197.                          ODFrame*            frame )
  198. {
  199.     SOM_Trace("Cappuccino","DoCopy");
  200.     
  201.     ASSERT_NOT_NULL(frame);
  202.  
  203.     TempClipboardFocus clipboardFocus(ev, frame);
  204.     if ( clipboardFocus.Request() )
  205.     {
  206.         ODClipboard* clipboard = fSession->GetClipboard(ev);
  207.         clipboard->Clear(ev);
  208.         
  209.         ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
  210.  
  211.         TRY
  212.             this->CloneContents(ev, clipboardSU, kODCloneCopy, frame, 
  213.                                 kIsForClipboard);
  214.         CATCH_ALL
  215.             clipboard->Clear(ev);
  216.             RERAISE;
  217.         ENDTRY
  218.     }
  219. }
  220.  
  221. //------------------------------------------------------------------------------
  222. // Method:        DoPaste
  223. // Origin:        Cappuccino
  224. //
  225. // Description:    This method is called by the part when the user chooses the
  226. //                Paste menu item.
  227. //------------------------------------------------------------------------------
  228.  
  229. void Cappuccino::DoPaste( Environment*            ev,
  230.                           ODFrame*                frame )
  231. {
  232.     SOM_Trace("Cappuccino","DoPaste");
  233.  
  234. #ifndef qViewerBuild
  235.     ASSERT_NOT_NULL(frame);
  236.  
  237.     if ( !this->TryToEdit(ev, frame) )
  238.         return;
  239.  
  240.     TempClipboardFocus clipboardFocus(ev, frame);
  241.     if ( clipboardFocus.Request() )
  242.     {
  243.         ODClipboard* clipboard = fSession->GetClipboard(ev);
  244.         ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
  245.         
  246.         // Get the new content from the clipboard's storage unit.
  247.         CCappuccinoContent* content = new CCappuccinoContent(this);
  248.         TempRefCounted contentTemp = content;
  249.         content->InitCappuccinoContent(ev, clipboardSU);
  250.         
  251.         CPasteAction* action = new CPasteAction(this, content);
  252.         action->Perform(ev);
  253.     }
  254. #endif
  255. }
  256.  
  257. //------------------------------------------------------------------------------
  258. // Method:        DoPasteAs
  259. // Origin:        Cappuccino
  260. //
  261. // Description:    This method is called by the part when the user chooses the
  262. //                Paste As... menu item.
  263. //------------------------------------------------------------------------------
  264.  
  265. void Cappuccino::DoPasteAs( Environment*            ev,
  266.                             ODFrame*                frame )
  267. {
  268.     SOM_Trace("Cappuccino","DoPaste");
  269.     
  270. #ifndef qViewerBuild
  271.     ASSERT_NOT_NULL(frame);
  272.  
  273.     if ( !this->TryToEdit(ev, frame) )
  274.         return;
  275.  
  276.     TempClipboardFocus clipboardFocus(ev, frame);
  277.     if ( clipboardFocus.Request() )
  278.     {
  279.         ODClipboard* clipboard = fSession->GetClipboard(ev);
  280.         
  281.         ODPasteAsResult        pasteAsResult;
  282.         pasteAsResult.selectedKind    = kODNULL;
  283.         pasteAsResult.translateKind    = kODNULL;
  284.         pasteAsResult.editor        = kODNULL;
  285.         TempODPasteAsResult    pasteAsResultTemp = &pasteAsResult;    
  286.         
  287.         // Parameters except pasteAsResult are omitted
  288.         if ( clipboard->ShowPasteAsDialog(ev,
  289.                                           kODTrue,                // canPasteLink
  290.                                           kODPasteAsMergeOnly,     // mergeSetting
  291.                                           this->GetActiveFacetForFrame(ev, frame),
  292.                                           kODNullTypeToken,        // viewtype
  293.                                           &pasteAsResult) )
  294.         {
  295.             ODStorageUnit* contentSU = clipboard->GetContentStorageUnit(ev);
  296.  
  297.             this->HandlePasteAsResult(ev, pasteAsResult, contentSU);
  298.         }
  299.     }
  300. #endif
  301. }
  302.     
  303. //------------------------------------------------------------------------------
  304. // Method:        DoClear
  305. // Origin:        Cappuccino
  306. //
  307. // Description:    This method is called by the part when the user chooses the
  308. //                Clear menu item.
  309. //------------------------------------------------------------------------------
  310.  
  311. void Cappuccino::DoClear( Environment*            ev,
  312.                           ODFrame*                frame )
  313. {
  314.     SOM_Trace("Cappuccino","DoClear");
  315.  
  316. #ifndef qViewerBuild
  317.     if ( !this->TryToEdit(ev, frame) )
  318.         return;
  319.     
  320.     CClearAction* action = new CClearAction(this);
  321.     action->Perform(ev);
  322. #endif
  323. }
  324.  
  325.